
gen dad_age = year-dob_year_dad
gen mom_age = year-dob_year_mom
gen parent_maxage = min(max(dad_age, mom_age,13),80) /*egg added 0 here*/

drop dob_year_mom dob_year_dad dad_age

/*sum parent_maxage, detail*/

gen i_obstaxyr = (year==1969 | year==1974 | year==1979 | year==1984 | year==1989 | inrange(year, 1994, 1995) | year>=1998 )
replace i_obstaxyr = . if year==.

merge m:1 year using ${supp_data}/eitc_params_yr, keep(match master) keepusing(cpi_2015 cpi_jan) gen(_m_cpi)
drop _m_cpi

/*
merge m:1 year using ${utility}/cpi\cpi_u, keepusing(jan cpi_2015) gen(_m_cpi_u) keep(match master)
rename jan cpi_jan
*/

foreach x in parent_agi parent_wage {
	rename `x' `x'_unadj

	gen `x' = `x'_unadj*(cpi_2015/cpi_jan)

	*Cap at 99 percentile (adjusted for inflation)
	summ `x', detail
	replace `x' =r(p99) if `x'>r(p99) & `x'!=.
	replace `x'_unadj =r(p99)*(cpi_jan/cpi_2015) if `x'>r(p99) & `x'!=.

	gen `x'z = `x'
	replace `x'z = 0 if parent_have_1040==0 & i_obstaxyr==1

	gen `x'z_unadj =`x'_unadj
	replace `x'z_unadj = 0 if parent_have_1040==0 & i_obstaxyr==1
}

gen parent_agiz_bin = ceil(parent_agiz/1000)*1000
replace parent_agiz_bin = ceil(parent_agiz/5000)*5000 if parent_agiz>40000
replace parent_agiz_bin = ceil(parent_agiz/10000)*10000 if parent_agiz>80000
replace parent_agiz_bin = 160000 if parent_agiz>150000 & parent_agiz!=.

/*egg, set negative AGI to 0*/
replace parent_agiz_bin = 0 if parent_agiz<0 & parent_agiz!=.
